Manage x and y ticks with xticks() and yticks() functions

Get the locations and labels like this


In [1]:
%pylab notebook
import matplotlib.pyplot as plt


Populating the interactive namespace from numpy and matplotlib
/Users/brodzik/.conda/envs/pmesdr/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

In [3]:
x = [5, 3, 7, 2, 4, 1]
plt.plot(x)
plt.xticks
locs, labels = plt.xticks()



In [5]:
locs


Out[5]:
array([ 0.,  1.,  2.,  3.,  4.,  5.])

In [8]:
print(labels)


<a list of 6 Text xticklabel objects>

In [9]:
plt.xticks(range(len(x)), ['a', 'b', 'c', 'd', 'e', 'f'])
plt.yticks(range(1, 8, 2))


Out[9]:
([<matplotlib.axis.YTick at 0x11011ca50>,
  <matplotlib.axis.YTick at 0x10fb4df10>,
  <matplotlib.axis.YTick at 0x11017b190>,
  <matplotlib.axis.YTick at 0x11017dad0>],
 <a list of 4 Text yticklabel objects>)

In [ ]: